
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace CUtil.Win32
{
	/// <summary> 
	/// 
	/// </summary>
	public class Shell32 
	{

		/// <summary> 
		/// Do not create instances of this class!
		/// </summary>
		private Shell32()
		{
		}
#region enums
#endregion enums
				
#region constants
		/// <summary></summary>
		public const int BIF_EDITBOX = 0x0010;
		/// <summary></summary>
		public const int BIF_NEWDIALOGSTYLE = 0x0040;
		/// <summary></summary>
		public const int BFFM_INITIALIZED = 1;
		/// <summary></summary>
		public const int BFFM_SELCHANGED = 2;
#endregion constants

#region callbacks
			/// <summary>
			/// Function delegate for browser callback function.
			/// </summary>
			public delegate int BFFCALLBACK(IntPtr hwnd, int msg, IntPtr/*LPARAM*/ lParam, IntPtr/*LPARAM*/ lpData);
#endregion callbacks

#region structs
			/// <summary>
			/// BROWSEINFO structure: passed to SHBrowseForFolder.
			/// </summary>
			[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
			public struct BROWSEINFO
			{
				/// <summary>...</summary>
				public IntPtr/*HWND*/ _hwndOwner;
				/// <summary>...</summary>
				public IntPtr/*LPCITEMIDLIST*/ _pidlRoot;
				/// <summary>...</summary>
				[MarshalAs(UnmanagedType.LPStr)] public string/*LPTSTR*/ _szDirectory;
				/// <summary>...</summary>
				[MarshalAs(UnmanagedType.LPStr)] public string/*LPCTSTR*/ _lpszTitle;
				/// <summary>...</summary>
				public uint/*UINT*/ _ulFlags;
				/// <summary>...</summary>
				[MarshalAs(UnmanagedType.FunctionPtr)] public BFFCALLBACK/*BFFCALLBACK*/ _lpfn;
				/// <summary>...</summary>
				public IntPtr/*LPARAM*/ _lParam;
				/// <summary>...</summary>
				public int/*int*/ _iImage;
			}   

			/// <summary>
			/// Memory management interface.
			/// </summary>
			[ComImport]
				[Guid("00000002-0000-0000-C000-000000000046")]
				[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
				public interface IMalloc
			{
				/// <summary>...</summary>
				[PreserveSig] IntPtr/*void * */ Alloc(ulong/*ULONG*/ cb);
				/// <summary>...</summary>
				[PreserveSig] IntPtr/*void * */ Realloc(IntPtr/*void * */ pv, ulong/*ULONG*/ cb);
				/// <summary>...</summary>
				[PreserveSig] void/*void*/ Free(IntPtr/*void * */ pv);
				/// <summary>...</summary>
				[PreserveSig] ulong/*ULONG*/ GetSize(IntPtr/*void * */ pv);
				/// <summary>...</summary>
				[PreserveSig] int/*int*/ DidAlloc(IntPtr/*void * */ pv);
				/// <summary>...</summary>
				[PreserveSig] void/*void*/ HeapMinimize();
			}
#endregion structs

#region functions
		//SHBrowseForFolder is not wrapped in the common.utils.win32 namespace because the struct BROWSEINFO
		//must be declared in this class.
		/// <summary>
		/// Display dialogue box to enable selection of shell folder.
		/// </summary>
		[DllImport("shell32.dll")]
		public static extern IntPtr/*LPITEMIDLIST*/ SHBrowseForFolder(ref BROWSEINFO/*LPBROWSEINFO*/ lpbi);

		/// <summary>
		/// Free memory allocated by shell.
		/// </summary>
		[DllImport("Shell32.dll")]
		public static extern int/*HRESULT*/ SHGetMalloc([MarshalAs(UnmanagedType.IUnknown)] out object /*LPMALLOC * */ ppMalloc);

		/// <summary>
		/// Convert an item identifier to a file system path.
		/// </summary>
		[DllImport("shell32.dll")]
		public static extern bool/*BOOL*/ SHGetPathFromIDList(IntPtr/*LPCITEMIDLIST*/ pidl, StringBuilder/*LPTSTR*/ pszPath);

#endregion functions
	}
}

